package br.com.onlinebidding.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(schema = "db_onlinebidding", name = "Edict")
@NamedQueries({
		@NamedQuery(name = "Edict.findEdictByName", query = "SELECT e FROM Edict e where e.name = :name"),
		@NamedQuery(name = "Edict.findEdictByDateTimeFinish", query = "SELECT e FROM Edict e where e.dateTimeFinish = :dateTimeFinish"), 
		@NamedQuery(name="Edict.findAllAssets",query="SELECT e FROM Edict e where e.dateTimeFinish >= :getDate")})
public class Edict implements Serializable {
	
	private static final long serialVersionUID = 7513376840914637377L;
	public static final String FIND_BY_NAME = "Edict.findEdictByName";
	public static final String FIND_BY_DATETIMEFINISH = "Edict.findEdictByDateTimeFinish";
	public static final String FIND_ALL_ASSETS = "Edict.findAllAssets";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@JoinColumn(name = "idProduct", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private Product idProduct;
	
	private String name;
	private String description;
	private Date dateTimeStart;
	private Date dateTimeFinish;
	private int amount;

	public int getId() {return id;}
	public void setId(int id) {this.id = id;}

	public String getName() {return name;}
	public void setName(String name) {this.name = name;}

	public String getDescription() {return description;}
	public void setDescription(String description) {this.description = description;}

	public Date getDateTimeStart() {return dateTimeStart;}
	public void setDateTimeStart(Date dateTimeStart) {this.dateTimeStart = dateTimeStart;}

	public Date getDateTimeFinish() {return dateTimeFinish;}
	public void setDateTimeFinish(Date dateTimeFinish) {this.dateTimeFinish = dateTimeFinish;}

	public int getAmount() {return amount;}
	public void setAmount(int amount) {this.amount = amount;}

	public void setIdProduct(Product idProduct) {this.idProduct = idProduct;}
	public Product getIdProduct() {return idProduct;}

	@Override
	public int hashCode() {return getId();}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Edict) {
			Edict edict = (Edict) obj;
			return edict.getId() == id;}
		return false;
	}
}